﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using DBBase;
using System.Windows.Forms;

namespace Business
{
    public partial class Configuration : Form
    {
        public MainForm m_mainform;
        public Configuration()
        {
            InitializeComponent();
        }

        private void but_query_Click(object sender, EventArgs e)
        {
            getjilu();
        }
        public void getjilu()
        {
            lv.Items.Clear();
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from PhotoChannel order by channel_line ");

            //try
            {
                DataTable dt = mquery.GetTable(sql);

                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        ListViewItem lt = new ListViewItem(string.Format("{0}", i + 1));
                        lt.SubItems.Add(dt.Rows[i]["channel_line"].ToString().Trim());
                        lt.SubItems.Add(dt.Rows[i]["channel_name"].ToString().Trim());
                        lt.SubItems.Add(dt.Rows[i]["channel_no"].ToString().Trim());
                        lt.SubItems.Add(dt.Rows[i]["channel_sbbh"].ToString().Trim());
                        this.lv.Items.Add(lt);
                    }
                }


            }
            string SQL = string.Format(@"select SI_SPWEB from StationInfor");
            DataTable DT = mquery.GetTable(SQL);

              if (DT.Rows.Count > 0)
              {
                  text_spweb.Text = DT.Rows[0]["SI_SPWEB"].ToString().Trim();
              }
             
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {

            Query mquery = new Query();
            string sql = string.Format(@" Select * from PhotoChannel where channel_name='{0}' and channel_line={1}", com_name.Text, com_line.Text);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sql = string.Format(@"update PhotoChannel set channel_no={0},channel_sbbh='{3}' where channel_line={1} and channel_name='{2}'", text_channel.Text, com_line.Text, com_name.Text, com_sbbh.Text);
            }
            else
            {
                sql = string.Format(@"insert into PhotoChannel (channel_line,channel_name,channel_no,channel_sbbh) values({0},'{1}',{2},'{3}')", com_line.Text, com_name.Text, text_channel.Text, com_sbbh.Text);
            }
            mquery.InsertDB(sql);

            getjilu();
        }
        private void skinButton3_Click(object sender, EventArgs e)
        {
            Query mquery = new Query();
            string SQL = string.Format(@"update StationInfor set SI_SPWEB='{0}'", text_spweb.Text);
            mquery.InsertDB(SQL);
            getjilu();

           
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            Query mquery = new Query();
            string sql = string.Format(@"delete PhotoChannel where channel_name='{0}'and channel_no={1} and channel_line={2}", com_name.Text, text_channel.Text, com_line.Text);
            mquery.InsertDB(sql);
            getjilu();
        }

        private void lv_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
           


        }

        private void Configuration_Load(object sender, EventArgs e)
        {
            getjilu();
        }

        private void lv_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem item in lv.SelectedItems)
            {
                com_line.Text = item.SubItems[1].Text.ToString().Trim();
                com_name.Text = item.SubItems[2].Text.ToString().Trim();
                text_channel.Text = item.SubItems[3].Text.ToString().Trim();
                com_sbbh.Text = item.SubItems[4].Text.ToString().Trim();
            }
        }

       

      

    }
}
